#include<stdio.h>
int main()
{
     char matrix[100][19];
     int n;
     scanf("%d",&n);
     for(int i=0;i<n;i++)
     {
         scanf("%s",matrix[i]);
     }
    int shuzu[17];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<17;j++)
        {
          shuzu[j]=matrix[i][j]-48;
        }
        char x;
        int sum;
        sum=shuzu[0]*7+shuzu[1]*9+shuzu[2]*10+shuzu[3]*5+shuzu[4]*8+shuzu[5]*4+shuzu[6]*2+shuzu[7]*1+shuzu[8]*6+shuzu[9]*3+shuzu[10]*7+shuzu[11]*9+shuzu[12]*10+shuzu[13]*5+shuzu[14]*8+shuzu[15]*4+shuzu[16]*2;
        sum=sum%11;
        switch(sum)
        {
            case 0:x='1';break;
            case 1:x='0';break;
            case 2:x='X';break;
            case 3:x='9';break;
            case 4:x='8';break;
            case 5:x='7';break;
            case 6:x='6';break;
            case 7:x='5';break;
            case 8:x='4';break;
            case 9:x='3';break;
            case 10:x='2';break;
            
        }
        if(x==matrix[i][17]) printf("right\n");
        else printf("wrong\n");
    }
   
    return 0;
}